//
//  KLFileTool.m
//  
//
//  Created by Tommy on 14/10/16.
//  Copyright (c) 2014年 com.taobao. All rights reserved.
//

#import "KLFileTool.h"

@implementation KLFileTool
+ (NSString *)homePath {
    return NSHomeDirectory();
}

+ (NSString *)desktopPath {
    return [NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}

+ (NSString *)documentPath {
    return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}

+ (NSString *)libPrePath{
    return [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingFormat:@"/Preference"];
}

+ (NSString *)libCachePath{
    return [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)objectAtIndex:0];
}

+ (NSString *)tmpPath{
    return [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingFormat:@"/tmp"];
}

+ (NSString *)appPath {
    return [[NSBundle mainBundle] bundlePath];
}

+ (NSString *)resourcePath {
    return [[NSBundle mainBundle] resourcePath];
}

+ (BOOL)touchPath:(NSString *)path
{
    if ( NO == [[NSFileManager defaultManager] fileExistsAtPath:path] )
    {
        return [[NSFileManager defaultManager] createDirectoryAtPath:path
                                         withIntermediateDirectories:YES
                                                          attributes:nil
                                                               error:NULL];
    }
    return YES;
}


+ (BOOL)touchFile:(NSString *)file
{
    if ( NO == [[NSFileManager defaultManager] fileExistsAtPath:file] )
    {
        return [[NSFileManager defaultManager] createFileAtPath:file
                                                       contents:[NSData data]
                                                     attributes:nil];
    }
    return YES;
}


+ (BOOL)fileExist:(NSString*)path{
    return  [[NSFileManager defaultManager] fileExistsAtPath:path];
}

@end
